<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>

    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">{{thtitle}}</div>
      </div>
      <!--  -->
      <!--  -->
      <div class="x-pro-list">
        <div class="x-pro-row">
          <div class="x-pro-label">萃取时间:</div>
          <div class="x-pro-input">
            <el-date-picker v-model="runtime" type="date" placeholder="选择日期" :editable="notkey" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" :disabled="isfromindex"></el-date-picker>
          </div>
        </div>
        <div class="x-pro-row">
            <div class="x-pro-label">案例主题:</div>
            <div class="x-pro-input">
                <el-input placeholder="请输入内容" v-model="runname" :disabled="isfromindex"></el-input>
            </div>
        </div>
        <div class="x-pro-row">
            <div class="x-pro-label">案例类型:</div>
            <div class="x-pro-input">
                <el-select v-model="runtype" placeholder="请选择" :disabled="isfromindex">
                <el-option v-for="item in runtypedata" :key="item.id" :label="item.title" :value="item.id"></el-option>
                </el-select>
            </div>
            </div>
            <div class="x-pro-row">
            <div class="x-pro-label">案例来源:</div>
            <div class="x-pro-input">
                <el-select v-model="runway" placeholder="请选择" :disabled="isfromindex">
                <el-option v-for="item in runwaydata" :key="item.id" :label="item.title" :value="item.id"></el-option>
                </el-select>
            </div>
        </div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">案例阐述:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="rundesc1" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row">
            <div class="x-pro-label">添加图片：</div>
            <div class="x-pro-input" style="align-self:center;padding:0 1rem;" v-if="!isfromindex">
              <el-button type="success" @click="imgPer">添加图片</el-button>
            </div>
        </div>
        <div>
            <div class="x-pro-himg" :style="{'background-image':'url(' +input4+ ')','background-size':'cover','width':'6rem','height':'6rem','border-radius':'0.4rem','margin-top':'1rem'}" v-if="input4!=''" @click="imagebig = true"></div>
        </div>
        
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">案例闪光点:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="rundesc2" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">应用价值:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="rundesc3" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        <div class="x-pro-row x-pro-rowblock">
          <div class="x-pro-label">案例适用:</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入内容" v-model="rundesc4" type="textarea" :rows="4" :disabled="isfromindex"></el-input>
          </div>
        </div>
        
      </div>
      <!--  -->
      <div class="x-pro-gobtn" @click="isok" v-if="thtype=='1'">提交</div>
      <div class="x-pro-gobtn" @click="isokthree" v-if="thtype=='3'">编辑</div>
      <div class="x-pro-gobtn x-disabled" @click="" v-if="thtype=='2'&&isyeslike>0">已推荐分享</div>
      <div class="x-pro-gobtn" @click="isoktwo" v-if="thtype=='2'&&isyeslike<=0">推荐分享</div>
      <img :src="input4" alt="" width="100%" v-if="imagebig" class="x-img-big" @click="imagebig = false">
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));
    var tmonth = api.pageParam.date;
    var ttype = api.pageParam.type;
    var tlistdesc = api.pageParam.listdesc;
    console.log(JSON.stringify(tlistdesc));
    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
            thtitle:'',
            thmonth:'',
            thtype:'',
            runtime:'',
            runname:'',
            runtype:'',
            runtypedata:'',
            runway:'',
            runwaydata:'',
            rundesc1:'',
            rundesc2:'',
            rundesc3:'',
            rundesc4:'',
            input4:'',
            runstore:'',
            isfromindex:false,
            storedata:'',
            typedata:'',
            waydata:'',
            notkey:false,
            thlistdesc:'',
            listid:'',
            isyeslike:'',
            //
            runsee1:'',
            runseeimg:'',
          imagebig:false

        }
      },
      created:function() {
        var that=this;
        that.thmonth = tmonth;
        that.thtype = ttype;
        that.getstoredata()// 类型data
        that.getstoredatatwo()// 来源data
        if(that.thtype == '1'){//新增
            that.thtitle = '添加经营指导';
        }else if(that.thtype == '2'){//查看
            that.isfromindex = true;
            that.thlistdesc = tlistdesc;
            that.thtitle = that.thlistdesc.title;//title
            that.listid = that.thlistdesc.id;
            that.isyeslike = that.thlistdesc.like_memberid;//>0推荐过
            //
            that.runtime = that.thlistdesc.in_time;
            that.runname = that.thlistdesc.title;
            that.runtype = that.thlistdesc.cateid;
            that.runway = that.thlistdesc.sourceid;
            that.rundesc1 = that.thlistdesc.content;
            that.input4 = that.thlistdesc.img;
            that.rundesc2 = that.thlistdesc.light_str;
            that.rundesc3 = that.thlistdesc.value_str;
            that.rundesc4 = that.thlistdesc.apply_str;

        }else if(that.thtype == '3'){//编辑
            that.isfromindex = false;
            that.thlistdesc = tlistdesc;
            that.thtitle = that.thlistdesc.title;//title
            that.listid = that.thlistdesc.id;
            //
            that.runtime = that.thlistdesc.in_time;
            that.runname = that.thlistdesc.title;
            that.runtype = that.thlistdesc.cateid;
            that.runway = that.thlistdesc.sourceid;
            that.rundesc1 = that.thlistdesc.content;
            that.input4 = that.thlistdesc.img;
            that.rundesc2 = that.thlistdesc.light_str;
            that.rundesc3 = that.thlistdesc.value_str;
            that.rundesc4 = that.thlistdesc.apply_str;

        }

      },
      mounted:function(){
        var that=this;

      },
      methods: {
          // 类型 select
        getstoredata:function(){
            let that=this;
            api.ajax({
                url:baseurl+'api/guide/caseCateList',
                methods:'get',
                data:{
                values:{
                    sec: $api.getStorage('apptoken')
                    }
                }
            },function(ret,err){
                if(ret){
                api.hideProgress();
                console.log(JSON.stringify(ret));
                if(ret.status == 1){
                    that.runtypedata = ret.data.list;
                }else{
                    api.toast({
                        msg: ret.msg,
                        duration: 3000,
                        location: 'bottom'
                    });
                }
                }else{
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: err.msg,
                    duration: 3000,
                    location: 'bottom'
                });
                }
            })
        },
        // 来源 select
        getstoredatatwo:function(){
            let that=this;
            api.ajax({
                url:baseurl+'api/guide/caseSourceList',
                methods:'get',
                data:{
                values:{
                    sec: $api.getStorage('apptoken')
                    }
                }
            },function(ret,err){
                if(ret){
                api.hideProgress();
                console.log(JSON.stringify(ret));
                if(ret.status == 1){
                    that.runwaydata = ret.data.list;
                }else{
                    api.toast({
                        msg: ret.msg,
                        duration: 3000,
                        location: 'bottom'
                    });
                }
                }else{
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: err.msg,
                    duration: 3000,
                    location: 'bottom'
                });
                }
            })
        },
        //
        isok:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/guide/addCase',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                in_time:that.runtime,
                title:that.runname,
                cateid:that.runtype,
                sourceid:that.runway,
                content:that.rundesc1,
                img:that.input4,
                light_str:that.rundesc2,
                value_str:that.rundesc3,
                apply_str:that.rundesc4,
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.sendEvent({
                    name: 'addcaseback',
                    extra: {
                    }
                });
                api.confirm({
                    title: '提交成功',
                    msg: '',
                    buttons: ['继续编辑', '返回']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if(index=='1'){

                    }else{
                      api.closeWin({});

                    }
                });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //推荐分享
        isoktwo:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/guide/likeCase',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.listid,
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.sendEvent({
                    name: 'addcaseback',
                    extra: {
                    }
                });
                api.confirm({
                    title: '推荐分享成功',
                    msg: '',
                    buttons: ['继续编辑', '返回']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if(index=='1'){
                        that.isyeslike = 1;
                    }else{
                      api.closeWin({});

                    }
                });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //编辑
        isokthree:function(){
            let that=this;
          api.ajax({
            url:baseurl+'api/guide/editCase',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.listid,
                in_time:that.runtime,
                title:that.runname,
                cateid:that.runtype,
                sourceid:that.runway,
                content:that.rundesc1,
                img:that.input4,
                light_str:that.rundesc2,
                value_str:that.rundesc3,
                apply_str:that.rundesc4,
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.sendEvent({
                    name: 'addcaseback',
                    extra: {
                    }
                });
                api.confirm({
                    title: '编辑成功',
                    msg: '',
                    buttons: ['继续编辑', '返回']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if(index=='1'){

                    }else{
                      api.closeWin({});

                    }
                });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        imgPer:function(){
          let that =this;
          var resultList = api.hasPermission({
              list:['camera','storage','photos']
          });
          if(!resultList[0].granted || !resultList[1].granted || !resultList[2].granted){
            // 没有权限
            that.reqPer()
          }else{
            // 有权限
            that.openpic()
          }
        },
        // 再请求
        reqPer:function(){
          let that =this;
          // 没有权限
          api.requestPermission({
              list:['camera','storage','photos'],
              code:1
          }, function(ret, err){
              if(ret.list[0].granted && ret.list[1].granted && ret.list[2].granted){
                // 允许
                that.openpic()
              }else{
                // 禁止
                that.noPer()
              }
              // 不再提醒
              if(ret.never){

              }
          });
        },
        // 禁止
        noPer:function(){
          let that =this;
          api.confirm({
            title: '提醒',
            msg: '没有获得 ' + '相机' + " 权限\n是否前往设置？",
            buttons: ['去设置', '取消']
          }, function(ret, err) {
            if(1 == ret.buttonIndex){
              that.reqPer();
            }
          });
        },
        //调起相机
        openpic:function(){
          let that =this;
          api.actionSheet({
              cancelTitle: '取消',
              buttons: ['相机', '相册']
          }, function(ret, err) {
              var tindex = ret.buttonIndex;
              if(tindex==1){//相机
                that.choicepic('camera')
              }else if(tindex==2){//相机
                that.choicepic('album')
              }
          });
        },
        //图片he视频上传
        choicepic:function(type){
          let that =this;
          api.getPicture({
            sourceType: type,
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: true,
            preview:true,
            quality: 50,
            saveToPhotoAlbum: true,
            groupName:'餐众邦'
          }, function(ret, err) {
            api.showProgress();
            if (ret) {
                console.log(JSON.stringify(ret));
                api.ajax({
                    url: baseurl+'upload/oss',
                    method: 'post',
                    data: {
                      values: {
                        "sec":$api.getStorage('apptoken'),
                      },
                      files: {
                        "file": ret.data
                      }
                    }
                }, function(ret, err) {
                  // console.log(JSON.stringify(ret));
                  // console.log(JSON.stringify(err));
                  api.hideProgress();
                  if(ret.status==1){
                    api.hideProgress();
                    // that.uploadvideo(ret.data[0].url)
                    that.input4 = ret.data[0].url;
                    // console.log(that.input4);


                  }else{
                    api.hideProgress();
                    api.toast({
                        msg: '上传失败，请重新选择',
                        duration: 3000,
                        location: 'bottom'
                    });
                  }
                });
            } else {
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: '上传失败，请重新选择',
                    duration: 3000,
                    location: 'bottom'
                });
            }
          });
        },
        
      }
    })
	}


	</script>
</body>
</html>
